package org.ysu.shoeShopping.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.ysu.shoeShopping.dao.PercontentDao;
import org.ysu.shoeShopping.entity.Percontent;
import org.ysu.shoeShopping.service.PercontentService;

import javax.annotation.Resource;

/**
 * 权限明细表(Percontent)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:59:23
 */
@Service("percontentService")
public class PercontentServiceImpl implements PercontentService
{
    @Resource
    private PercontentDao percontentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pcid 主键
     * @return 实例对象
     */
    @Override
    public Percontent queryById(Integer pcid) {
        return this.percontentDao.queryById(pcid);
    }

    /**
     * 分页查询
     *
     * @param percontent 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Percontent> queryByPage(Percontent percontent, PageRequest pageRequest) {
        long total = this.percontentDao.count(percontent);
        return new PageImpl<>(this.percontentDao.queryAllByLimit(percontent, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param percontent 实例对象
     * @return 实例对象
     */
    @Override
    public Percontent insert(Percontent percontent) {
        this.percontentDao.insert(percontent);
        return percontent;
    }

    /**
     * 修改数据
     *
     * @param percontent 实例对象
     * @return 实例对象
     */
    @Override
    public Percontent update(Percontent percontent) {
        this.percontentDao.update(percontent);
        return this.queryById(percontent.getPcid());
    }

    /**
     * 通过主键删除数据
     *
     * @param pcid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pcid) {
        return this.percontentDao.deleteById(pcid) > 0;
    }
}
